﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using INHSStudentRegistration;

namespace IrisanNHS
{
    public partial class Form5 : Form
    {
        MainForm parent;

        DataTable DT = new DataTable();

        DataBaseConnection DBC = new DataBaseConnection();
        UserAccount UAccount = new UserAccount();
        public int InDeX;

        public Form5(MainForm p)
        {
            InitializeComponent();
            parent = p;
            this.Load += new EventHandler(Form5_Load);
            btnadduser.Click += new EventHandler(btnadduser_Click);
        }

        private void registeruser()
        {
            try
            {
                UAccount.UID = txtUID.Text;
                UAccount.uaname = txtname.Text;
                UAccount.uauname = txtusername.Text;
                UAccount.uapassword = txtpassword.Text;
                UAccount.cpassword = txtpassword.Text;
                UAccount.lvlofaccess = comboBoxlvlofaccess.Text;
                
                DBC.UserAccount(UAccount);
                MessageBox.Show("Successfully Saved");
            }
            catch (Exception)
            {
                MessageBox.Show("Complete the  Account Registration");
                return;
            }
        }

        void btnadduser_Click(object sender, EventArgs e)
        {
            registeruser();

            txtUID.Text = "";
            txtname.Text = "";
            txtusername.Text = "";
            txtpassword.Text = "";
            txtpassword.Text = "";
            comboBoxlvlofaccess.Text = "";
        }

        void Form5_Load(object sender, EventArgs e)
        {
            DBC.DBConnection();
            DBC.MyQuery("SELECT * FROM accounttable");
            DT = DBC.DT;
            DBC.Close();
        }
    }
}
